use ".\data\clean\I10_Feb_Dec_Dataclean.dta", clear
capture drop dir
g dir=substr(entry_plaza,1,1)
drop if dir=="E"
rename entry_hour hour
ren entry_date date


g rt_id=cond(entry_plaza=="WT01" & exit_plaza=="WT01",1, ///
	cond(entry_plaza=="WT01" & exit_plaza=="WT03",2, ///
	cond(entry_plaza=="WT01" & exit_plaza=="WT04" ,3, ///
	cond(entry_plaza=="WT01" & exit_plaza=="WT05" ,4, ///
	cond(entry_plaza=="WT01" & exit_plaza=="WT06" ,5, ///
	cond(entry_plaza=="WT02" & exit_plaza=="WT02" ,6, ///
	cond(entry_plaza=="WT02" & exit_plaza=="WT03" ,7, ///
	cond(entry_plaza=="WT02" & exit_plaza=="WT04" ,8, ///
	cond(entry_plaza=="WT02" & exit_plaza=="WT05" ,9, ///
	cond(entry_plaza=="WT02" & exit_plaza=="WT06" ,10, ///
	cond(entry_plaza=="WT03" & exit_plaza=="WT03" ,11, ///
	cond(entry_plaza=="WT03" & exit_plaza=="WT04" ,12, ///
	cond(entry_plaza=="WT03" & exit_plaza=="WT05" ,13, ///
	cond(entry_plaza=="WT03" & exit_plaza=="WT06" ,14, ///
	cond(entry_plaza=="WT04" & exit_plaza=="WT04" ,15, ///
	cond(entry_plaza=="WT05" & exit_plaza=="WT05", 16, ///
	cond(entry_plaza=="WT05" & exit_plaza=="WT06", 17, ///
	cond(entry_plaza=="WT06" & exit_plaza=="WT06", 18,.))))))))))))))))))

	
g min=mm(entry_time)
g min5=cond(min<=5,0, ///
	cond(min<=10,5, ///
	 cond(min<=15,10, ///
	 cond(min<=20,15, ///
	 cond(min<=25,20, ///
	 cond(min<=30,25, ///
	 cond(min<=35,30,  ///
	cond(min<=40,35,  ///
	cond(min<45, 40,  ///
	cond(min<=50,45,  ///
	cond(min<=55,50,  ///
	cond(min<=60,55,.))))))))))))
	/*
g dist=cond( rt_id==2,3.52, ///
	cond(rt_id==3,6.22,	///
	cond(rt_id==4,6.58,		///
	cond(rt_id==5,9.68,	///
	cond(rt_id==7 ,.97,		///
	cond(rt_id==8 ,3.67,	///
	cond(rt_id==9 , 4.03,	///
	cond(rt_id==10, 7.13,	///
	cond(rt_id==12, 2.7, ///
	cond(rt_id==13, 3.06, ///
	cond(rt_id==14, 6.16, ///
	cond(rt_id==17,3.1,.))))))))))))
	*/
g SOVcount=cond(occupancy=="SOV" & acct_type=="PRIVATE",1,0)
g HOV3count=cond(occupancy=="HOV-2" & acct_type=="PRIVATE",1,0)
g HOV2count=cond(occupancy=="HOV-3" & acct_type=="PRIVATE",1,0)
g VIOLcount=cond(trx_type=="VIOL",1,0)
g NON_REVcount=cond(trx_type=="NON_REV",1,0)
g acct_type2=trim(acct_type)
g BUSINESScount=cond(acct_type2=="BUSINESS",1,0)
g PRIVATEcount=cond(acct_type2=="PRIVATE",1,0)
g OtherTranscount=cond(trx_type=="CTOC",1,0)	
g TOTALcount=1
g totaltoll=cond(charged_toll>0, charged_toll,.)
drop min
ren min5 min
g holiday=0
*NY
replace holiday=1 if date==td(01jan2013) | date==td(01jan2012) | date==td(31dec2012) | date==td(31dec2011)
*MLK
replace holiday=1 if date==td(21jan2013) | date==td(16jan2012)
*President's Day
replace holiday=1 if date==td(20feb2012) | date==td(18feb2013)
* Easter week
replace holiday=1 if date >= td(2apr2012) & date <= td(8apr2012)
replace holiday=1 if date >= td(26mar2013) & date <= td(31mar2013)
*Memorial Day
replace holiday=1 if date==td(28may2012) | date==td(27may2013)
*4th of July
replace holiday=1 if date==td(04jul2012) | date==td(04jul2013)
* Labor Day
replace holiday=1 if date==td(03sep2012) | date==td(05sep2011) | date==td(02sep2013)
* Columbus Day
replace holiday=1 if date==td(08oct2012) | date==td(10oct2011) | date==td(14oct2013)
* Veteran's Day
replace holiday=1 if date==td(11nov2012) | date==td(11nov2011) | date==td(11nov2013)
* Thanksgiving week
replace holiday=1 if date >= td(22nov2011) & date <= td(26nov2011)
replace holiday=1 if date >= td(19nov2012) & date <= td(23nov2012)
replace holiday=1 if date >= td(25nov2013) & date <= td(30nov2013)
* Christmas week
replace holiday=1 if date >= td(24dec2011) & date <= td(31dec2011)
replace holiday=1 if date >= td(24dec2012) & date <= td(31dec2012)
replace holiday=1 if date >= td(24dec2013) & date <= td(31dec2013)
drop if holiday==1
drop holiday
g dow=dow(date)
drop if dow==0 | dow==6
sort rt_id date hour min
g entry_pm=cond(entry_plaza=="WT01",27.84 , ///
		cond(entry_plaza=="WT02",25.29 , ///
		cond(entry_plaza=="WT03",24.32 , ///
		cond(entry_plaza=="WT04",21.62 , ///
		cond(entry_plaza=="WT05", 21.26, ///
		cond(entry_plaza=="WT06", 18.16,.))))))
								
g exit_pm=cond(exit_plaza=="WT01",27.84 , ///
		cond(exit_plaza=="WT02",25.29 , ///
		cond(exit_plaza=="WT03",24.32 , ///
		cond(exit_plaza=="WT04",21.62 , ///
		cond(exit_plaza=="WT05", 21.26, ///
		cond(exit_plaza=="WT06", 18.16,.))))))
		
g dist=entry_pm-exit_pm
replace dist=. if dist==0
g time=(exit_time-entry_time)/1000
drop if time<0
replace time=. if time==0
g  ELspeed=dist/(time/(60*60))
replace ELspeed=. if travtime<2.87 | travtime>11
replace ELspeed=. if ELspeed>150
la var ELspeed "Implied Vehicle Speed from EL Timestamps (mph)"
merge rt_id date hour min using "\\rschfs1x\userrs\arw227_RS\Documents\expresslanes\Winter2014\Winter2014\cleandata\I10_speedflow_premerge", uniqusing
tab _m
drop if _m!=3
compress
g HVTT=60*10.5/HVspeed
g MLTT=60*10.5/MLspeed
g TTdiff=MLTT-HVTT
gen VOT=charged_toll/(TTdiff/60) if charged_toll!=0
gen VOT20=20/(TTdiff/60) if charged_toll!=0

g count=1
g ELTT=60*10.5/ELspeed
g TTdiff_ELSpeed=MLTT-ELTT
gen VOT_ELSpeed=charged_toll/(TTdiff_ELSpeed/60) if charged_toll!=0
gen VOT_ELSpeed20=20/(TTdiff_ELSpeed/60) if charged_toll!=0
capture drop period
g period=cond(hour>4 & hour<10, "AM Peak", cond(hour>9 & hour<16, "PM Off-Peak", cond(hour>15 & hour<20, "PM Peak","Eve. Off-Peak")))


replace MLflow=MLflow/12
drop *count _m totaltoll license
la var date "date of EL entry"
la var hour "hour of EL entry"
la var min "5 min interval of EL entry"
la var charged_toll "Avg. Total toll paid ($)"
la var VOT_ELSpeed "VOT ($/hr) from transponder speeds and tolls paid"
la var VOT_ELSpeed20 "VOT ($/hr) from transponder speeds and $20/hr VOT assumption"
la var VOT "VOT ($/hr) based on PeMS speeds and tolls paid"
la var VOT20 "VOT ($/hr) based on PeMS speeds and $20/hr VOT assumption"

la var ELspeed "Speed from transponder data (mph)"
la var TTdiff "travel time difference from PeMS data (min.)"
la var TTdiff_ELSpeed "travel time difference from transponder speed in HOV and ML speed from PeMS(min.)"
la var HVTT "PeMS HOV Travel Time for 10.5mi"
la var MLTT "PeMS ML Travel TIme for 10.5mi"
la var ELTT "Transponder Data Travel time for 10.5mi"

save ".\data\clean\laneuse_dataset_19aug14.dta", replace

